﻿// -----------------------------------------------------------------------
// <copyright file="CustomLabel.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.ControlBuilders
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    using Gui.ThemeEngine;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomLabel : BaseControl
    {
        /// <summary>
        /// Create the custom control
        /// </summary>
        /// <param name="controlProperties">The Xml node that contains the control properties</param>
        /// <returns>Returns custom control</returns>
        public Controls.MetalLabel GetControl(XmlNode controlProperties)
        {
            Controls.MetalLabel customLabel = new Controls.MetalLabel();

            // Apply common properties
            this.BuildControl(controlProperties, customLabel as Control);

            // Apply specific control properties
            string alignment = PropertyProvider.GetValue(controlProperties, "textAlign", "Left");
            if (alignment == "Right")
            {
                customLabel.TextAlign = ContentAlignment.MiddleRight;
            }

            customLabel.BackColor = PropertyProvider.GetValue(controlProperties, "backColor");
            customLabel.ForeColor = PropertyProvider.GetValue(controlProperties, "foreColor");

            FontStyle style = (FontStyle)Enum.Parse(typeof(FontStyle), PropertyProvider.GetValue(controlProperties, "fontStyle", "Regular"));
            (customLabel as Gui.Controls.MetalLabel).SetFont(PropertyProvider.GetValue(controlProperties, "font", "Default"), PropertyProvider.GetValue(controlProperties, "fontSize", 10), style);

            customLabel.DataBindings.Add("Text", Metal.Data.DataStorage.Table, PropertyProvider.GetValue(controlProperties, "dataSource", string.Empty));

            return customLabel;
        }

        /// <summary>
        /// Apply common properties
        /// </summary>
        /// <param name="control">The Xml node that contains our control properties</param>
        /// <param name="customControl">The custom control that will be created</param>
        public override void BuildControl(System.Xml.XmlNode control, System.Windows.Forms.Control customControl)
        {
            base.BuildControl(control, customControl);
        }
    }
}
